package com.castile.sdk.nifi.client;

import com.castile.sdk.nifi.client.api.DIONiFiServiceFactory;
import com.castile.sdk.nifi.client.api.NiFiClientService;
import com.castile.sdk.nifi.client.api.NiFiServiceFactory;
import com.castile.sdk.nifi.client.config.ConfigCenterNiFiConfigManager;
import com.castile.sdk.nifi.client.config.NiFiConfig;
import com.castile.sdk.nifi.client.config.NiFiConfigManager;
import com.castile.sdk.nifi.client.exception.NiFiClientCreateException;
import lombok.extern.flogger.Flogger;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.function.Supplier;

/**
 * @author castile
 * @date 2025-05-18 下午9:06
 */
@Service
@Slf4j
public class NiFiClientManager {

    @Qualifier("local-nifi-config-manager")
    @Autowired
    private NiFiConfigManager configManager;

    @Autowired
    private NiFiServiceFactory<NiFiClientService> serviceFactory;


    /**
     * 根据nifi集群id创建 nifiClientService
     *
     * @param id nifi集群id
     * @return nifiClientService
     */
    public NiFiClientService getClientById(String id){
        NiFiClientService niFiService = null;
        NiFiConfig niFiConfig = configManager.getNiFiConfig(id);
        try {
            niFiService = serviceFactory.createNiFiService(niFiConfig);
        } catch (NiFiClientCreateException e) {
            log.error("NiFiClientCreateException:{}",e);
        }
        return niFiService;
    }
}
